package sis.studentinfo;

import junit.framework.*;

public class StudentTest extends TestCase{
	private static final double GRADE_TOLERANCE = 0.05;
	
	public void testCreate(){
		final String firstStudentName = "Jane Doe";
		Student firstStudent = new Student(firstStudentName);
		assertEquals (firstStudentName, firstStudent.getName());
		assertEquals ("Jane", firstStudent.getFirstName());
		assertEquals ("Doe", firstStudent.getLastName());
		assertEquals ("", firstStudent.getMiddleName());
		
		final String secondStudentName = "Blow";
		Student secondStudent = new Student(secondStudentName);
		assertEquals (secondStudentName, secondStudent.getName());
		assertEquals ("", secondStudent.getFirstName());
		assertEquals ("Blow", secondStudent.getLastName());
		assertEquals ("", secondStudent.getMiddleName());
		
		final String thirtStudentName = "Raymond Douglas Davies";
		Student thirtStudent = new Student (thirtStudentName);
		assertEquals ("Raymond", thirtStudent.getFirstName());
		assertEquals ("Davies", thirtStudent.getLastName());
		assertEquals ("Douglas", thirtStudent.getMiddleName());
	}
	
	public void testStudentStatus() {
		Student student = new Student("a");
		assertEquals(0, student.getCredits());
		assertFalse(student.isFullTime());
		
		student.addCredits(3);
		assertEquals(3, student.getCredits());
		assertFalse(student.isFullTime());
		
		student.addCredits(4);
		assertEquals(7, student.getCredits());
		assertFalse(student.isFullTime());
		
		student.addCredits(5);
		assertEquals(Student.CREDITS_REQUIRED_FOR_FULL_TIME,
			student.getCredits());
		assertTrue(student.isFullTime());		
	}
	
	public void testInState() {
		Student student = new Student("a");
		assertFalse(student.isFullTime());
		student.setState(Student.IN_STATE);
		assertTrue(student.isInState());
		student.setState("MD");
		assertFalse(student.isInState());
	}
	
	public void testCalculateGpa() {
		Student student = new Student("a");
		assertGpa(student, 0.0);
		student.addGrade(Student.Grade.A);
		assertGpa(student, 4.0);
		student.addGrade(Student.Grade.B);
		assertGpa(student, 3.5);
		student.addGrade(Student.Grade.C);
		assertGpa(student, 3.0);
		student.addGrade(Student.Grade.D);
		assertGpa(student, 2.5);
		student.addGrade(Student.Grade.F);
		assertGpa(student, 2.0);
	}
	
	private void assertGpa(Student student, double expectedGpa) {
		assertEquals(expectedGpa, student.getGpa(), GRADE_TOLERANCE);
	}
}
